package com.eztalks.demo;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class MQCumsutor implements MessageListener {
	static ActiveMQConnectionFactory activeMQConnectionFactory = null;
	static Connection connection1 = null;
	static {
		try {
			activeMQConnectionFactory = new ActiveMQConnectionFactory("failover:(tcp://120.26.132.173:61616)");
			connection1 = activeMQConnectionFactory.createConnection("root", "123456");
			connection1.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws Exception {
		try {
			Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
			Queue custormer = session1.createQueue("vodserver_pushstream_notify");
			MessageConsumer createConsumer = session1.createConsumer(custormer);
			createConsumer.setMessageListener(new MQCumsutor());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void onMessage(Message message) {
		try {
			if (message instanceof TextMessage) {
				TextMessage textMessage = (TextMessage) message;
				String messageStr = textMessage.getText();
				System.out.println(messageStr);
			}

		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
